@echo off
REM Package Steamauto using PyInstaller and build.spec
REM This version always uses the current environment's python

REM Clean build, dist, cache files before packaging
rmdir /s /q build 2>nul
rmdir /s /q dist 2>nul
rmdir /s /q __pycache__ 2>nul
rmdir /s /q .pytest_cache 2>nul
rmdir /s /q .mypy_cache 2>nul
REM Do not delete build.spec to avoid packaging errors

echo Cleaned build, dist, and cache files.

REM Install pyinstaller if not present
python -m pip show pyinstaller >nul 2>nul
if %errorlevel% neq 0 (
    echo PyInstaller is not installed. Installing now...
    python -m pip install pyinstaller -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
)

REM Start packaging using python -m PyInstaller
python -m PyInstaller build.spec

if %errorlevel% neq 0 (
    echo Packaging failed. Please check for errors.
    pause
    exit /b 1
) else (
    echo Packaging completed successfully! The executable is in the dist folder.
    pause
)
